package jenetics.test;

import java.util.Random;
import java.util.stream.Collector;

import org.jenetics.util.RandomRegistry;

public final class Item {

	public final double size;
	public final double value;
	
	public Item(double size, double value) {
		this.size = size;
		this.value = value;
	}
	
	static Item random() {
		final Random r = RandomRegistry.getRandom();
		return new Item(r.nextDouble() * 100, r.nextDouble() * 100);
	}
	
	static Collector<Item, ?, Item> toSum() {
		return Collector.of(() -> new double[2], (a, b) -> {a[0] += b.size; a[1] += b.value;}, (a, b) -> {a[0] += b[0]; a[1] += b[1]; return a;}, r -> new Item(r[0], r[1]));
	}
	
}